#ifndef INIFILEHELPER_H
#define INIFILEHELPER_H

#include <QObject>
#include <QFile>
#include <qdebug.h>

static  QString ApplicationPath = "/LevelForSteel.ini";
static  QString width1 = "\\\\192.168.2.100//Width1//%1//width.txt";
static  QString width2 = "\\\\192.168.2.100//Width2//%1//width.txt";
static  QString width3 = "\\\\192.168.2.100//Width3//%1//width.txt";
static  QString width4 = "\\\\192.168.2.100//Width4//%1//width.txt";
/*static  QString width1 = "E://widths//width1//width.txt";
static  QString width2 = "E://widths//width2//width.txt";
static  QString width3 = "E://widths//width3//width.txt";
static  QString width4 = "E://widths//width4//width.txt"*/;

// 静态读取宽度文件信息 通过路径和缺陷图片索引查找到正确的数据
[[maybe_unused]]
static QList<int> readFile(QString File_width,int imgIndex)
{
    QFile file(File_width);
    QList<int> readRes;
    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
        qDebug()<<"找不到宽度文件";
        return {0,0,0,0};
    }
    while (!file.atEnd()) {
        auto widthFileList =QString(file.readLine()).split(QLatin1Char('&'));
        if(widthFileList.size()>0){
            if(widthFileList.count() == 4 && (imgIndex == widthFileList[3].toInt()) ){
                readRes<<widthFileList[0].toInt() <<widthFileList[1].toInt()<<widthFileList[2].toInt()<<widthFileList[3].toInt();
            }
        }
        else
        {
            file.close();
            return {0,0,0,0};
        }

    }
    file.close();
    return readRes;
}

/**
 * @brief 程序运行时的基础设置
 */
class IniFilehelper : public QObject
{
    Q_OBJECT
public:
   using QObject::QObject;

    bool  ReadIni(const QString &Path);
    bool  WriteIni(const QString &Path);

public :
    //数据库连接信息
    static QString hostName;
    static QString User;
    static QString Pwd;
    static int camNum; //当前使用的相机数量

    //通信信息
    static QString tcpIp;
    static int tcpPort;

    //判级信息
    static int ignoreMeter;
};

#endif // INIFILEHELPER_H
